package com.qingke.memo.command.system;

import java.util.List;

import com.qingke.memo.app.MemorandumApplication;
import com.qingke.memo.command.SystemCommand;
import com.qingke.memo.pojo.Memo;
import com.qingke.memo.unit.MConsole;

public class GoToMemo extends SystemCommand {

	@Override
	public void execute() {
		List<Memo> list=dao.selectAllMemos();
		if(list.size()==0){
			MConsole.println("no memo");
			return ;
		}
		MConsole.println();
		for(Memo m:list){
			MConsole.println("[id]:"+m.getId()+",[title]:"+m.getTitle()+",[create time]:"+m.getCreateTime());
		}
		MConsole.println();
		
		int id=MConsole.getInt("memo id:");
		if(!dao.isMemoExistById(id)){
			MConsole.println("the memo is not existed.");
			return ;
		}
		
		Memo memo=dao.selectMemoById(id);
		MemorandumApplication.getInstance().setMemo(memo);
		MConsole.println("into memo success");
	}

}
